#ifndef SWITCH_H 
#define SWITCH_H

#include "Vertex.h"
#include "RankSet.h"
#include "Group.h"
#include "VertexDirectory.h"
#include "Helpers.h"
#include "Chain.h"
#include <cstdlib>

class SwitchVerticesAlgorithm 
{
public:
	SwitchVerticesAlgorithm(Chain *inputChain, unsigned int maxInterchangeables = 45);
	Chain* SwitchSingles();
	Chain* SwitchCouples();


private:
	void FindReplacementsForWholeChain(Chain *chain);
	void FillReplacements(Group *group);
	void FillVertexSetReplacements(Chain *chain);

	void PutInterchangeablesBackInGraph(Chain *workingChain);
	void PutInterchangeableVertexSetsInGraph(Chain *workingChain);

	void ReturnRemainingInterchangeablesToGroups(Graph *graph,VertexDirectory *dir);
	void ReturnRemainingInterchangeableVertexSetsToGroups(Graph *graph);

	void ImproveGroups(Chain *workingChain, bool switchSingles);

	Group *RunGreedyAlgorithm(Chain *chain, Group *group);
	Group *RunCouplesGreedyAlgorithm(Chain *chain, Group *group);

	void MakeNecessaryReplacements(VertexDirectory *dir, Graph *graph);
	void MakeNecessaryReplacementsForVertexSets(Graph *graph);

	void ClearAllInterchangeableInformation(VertexDirectory *dir);

	set<VertexKey> m_InterchangeableVertices;
	set<VertexSetKey> m_InterchangeableVertexSets;
	set<VertexKey> m_ReplacementVertices;
	unsigned int m_MaxInterchangeables;
	Chain* m_Chain;

};

#endif
